<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 3. 面试题

        // 写一个函数，从一个非纯数字的数组中，得到第k大数字，重复数字并列排名


        // 筛选数值型  
        function arrNumber(arr) {
            let res = []
            for (let i = 0; i < arr.length; i++) {
                if (typeof (arr[i]) === "number") {
                    res.push(arr[i])
                }
            }

            return res
        }


        // 冒泡排序
        function sort(arr) {
            for (let i = 0; i < arr.length - 1; i++) {

                for (let j = 0; j < arr.length - 1 - i; j++) {
                    if (arr[j] < arr[j + 1]) {
                        let tmp = arr[j]
                        arr[j] = arr[j + 1]
                        arr[j + 1] = tmp
                    }
                }

            }

            return arr
        }

        // 筛选第k大值， 排序数组
        function arrSort(k, arr) {
            let res = sort(arrNumber(arr))
            let newArr = []
            for (let i = 0; i < res.length; i++) {
                if (!newArr.includes(res[i])) {
                    newArr.push(res[i])
                }
            }
            return {
                k: newArr[k - 1],
                arrAgain: res,
                arr:newArr
            }
        }

        console.log(arrSort(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 'h', 'o', '2', true, 1, 3, 2, 5, 4]));
    </script>
</body>

</html>